package online.hxstart.code.concurrent.chapter02;

import java.util.stream.IntStream;

/**
 * @author huxing
 * @date 19-4-22 星期一 下午4:42
 * @describe
 */
public class ThreadConstruction1 {

  private static final String PREFIX = "ALEX-";

  public static void main(String[] args) {
    Thread t1 = new Thread("t1");
    ThreadGroup group = new ThreadGroup("threadGroup");
    Thread t2 = new Thread(group, "T2");
    ThreadGroup mainThreadGroup = Thread.currentThread().getThreadGroup();
    System.out.println("Main thread belong group：" + (mainThreadGroup == t1.getThreadGroup()));
    System.out.println(
        "t1 and main belong the same group：" + (mainThreadGroup == t1.getThreadGroup()));
    System.out.println(
        "t2 thread group not belong main group：" + (mainThreadGroup == t1.getThreadGroup()));
    System.out.println("t2 thread group belong main TestGroup：" + (group == t2.getThreadGroup()));
    IntStream.range(0, 5).mapToObj(ThreadConstruction1::createThread).forEach(Thread::start);
  }

  private static Thread createThread(final int intName) {
    return new Thread(() -> System.out.println(Thread.currentThread().getName()), PREFIX + intName);
  }
}
